package com.woniuxy.nio.channel.filechannel;

import com.woniuxy.nio.util.FileUtils;

import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO: transferTo() 实现通道之间的传输
 * <P> Date: 2022/4/3:11:00
 * <P> Description:
 */

public class FileChannelFileTransferToTest {
    public static void main(String[] args) throws Exception {
        //TODO 1.创建 两个通道
        RandomAccessFile aFile =
                new RandomAccessFile(FileUtils.FILE_TARGET, "rw");
        FileChannel fromChannel = aFile.getChannel();

        RandomAccessFile bFile =
                new RandomAccessFile(FileUtils.FILE_SOURCE, "rw");
        FileChannel toChannel = bFile.getChannel();

        long position = 0;
        long size = fromChannel.size();
        fromChannel.transferTo(0,size,toChannel);



        aFile.close();
        bFile.close();
        System.out.println("over");
    }
}
